to calculate velocity and acceleration